import React,{useState} from 'react';
import {Route, Switch} from "react-router-dom";
import { lazy } from 'react';
import L from '../../../L';
import ContentLoading from '../../../components/contentLoading'
// 欢迎页
import Welcome from '../../Welcome'
// import BusinessMessageManage from './BusinessMessageManage';
// import DeviceManage from './DeviceManage';
// import FeedbackManage from './FeedbackManage';
// import PropertyMessageManage from './PropertyMessageManage';

import Message from '../../../components/message'
// 商业活动管理
const BusinessMessageManage = lazy(() => import(`./BusinessMessageManage`))
// 物业通知管理
const PropertyMessageManage = lazy(() => import(`./PropertyMessageManage`))
// 设备管理
const DeviceManage = lazy(() => import(`./DeviceManage`))
// 意见反馈
const FeedbackManage = lazy(() => import(`./FeedbackManage`))


function LL(props){
    return <L Loading={ContentLoading}>{props.children}</L>
}


function Content() {
    const [newMessageShow, setNewMessageShow] = useState(false);
    const [selectPeopleShow, setSelectPeopleShow] = useState(false);
    const success = 'success';
    const error   = 'error';
    const warning = 'warning';
    const info    = 'info';
    // 消息框四要素，是否打开 | 消息内容 | 消息类型 | 关闭函数
    const [message, setmessage] = useState({
        open:false,
        text:'',
        type:success,
        onClose:function(){}
    });
    // 关闭消息框
    function closeMessage(){
        setmessage({
            ...message,
            open:false,
        });
    }


    React.useEffect(() =>{
        setmessage({
            ...message,
            onClose:closeMessage
        })
    },[])

    return (
        <React.Fragment>
            <Switch>
                <Route 
                    path="/BusinessMessageManage" 
                    render={(props) => {
                        var _props = {
                            ...props,
                            success,
                            error,
                            warning,
                            info,
                            newMessageShow,
                            setNewMessageShow,
                            selectPeopleShow,
                            setSelectPeopleShow,
                            message,
                            setmessage
                        }
                        // return <BusinessMessageManage {..._props} />
                        return <LL><BusinessMessageManage {..._props} /></LL>
                    }}
                >
                </Route>
                <Route 
                    path="/PropertyMessageManage" 
                    render={
                        (props) =>{
                            var _props = {
                                ...props,
                                success,
                                error,
                                warning,
                                info,
                                newMessageShow,
                                setNewMessageShow,
                                selectPeopleShow,
                                setSelectPeopleShow,
                                message,
                                setmessage
                            }
                            // return <PropertyMessageManage {..._props} />
                            return <LL><PropertyMessageManage {..._props} /></LL>
                        }
                    }
                >
                </Route>
                <Route 
                    path="/DeviceManage"  
                    // component={DeviceManage}
                    render={(props) => <LL><DeviceManage {...props} /></LL>}
                >
                </Route>
                <Route 
                    path="/FeedbackManage" 
                    // component={FeedbackManage}
                    render={(props) => <LL><FeedbackManage {...props} /></LL>}
                >
                </Route>
                <Route path="/" component={Welcome}></Route>
            </Switch>
            <Message {...message}></Message>
        </React.Fragment>
    )
}

export default Content